package com.prd.controller;


import com.prd.dto.CustomerFollowDTO;
import com.prd.service.CustomerFollowService;
import com.prd.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 客户-跟进 前端控制器
 * </p>
 *
 * @author o1
 * @since 2024-01-02
 */
@Api(tags={"客户管理-跟进"})
@RestController
@RequestMapping("/customerFollowDO")
public class CustomerFollowController {

    private CustomerFollowService followService;

    public CustomerFollowController(CustomerFollowService followService) {
        this.followService = followService;
    }

    @ApiOperation("客户模块-跟进列表-分页列表")
    @GetMapping("page")
    public JsonData page(
            @ApiParam(value = "当前页数") @RequestParam(value = "page", defaultValue = "1") int page,
            @ApiParam(value = "当页数目") @RequestParam(value = "size", defaultValue = "10") int size,
            @ApiParam(value = "日期") @RequestParam(value = "date", defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM") Date date,
            @ApiParam(value = "员工id，既业务负责人id") @RequestParam(value = "businessManagerId", defaultValue = "-1") int businessManagerId,
            @ApiParam(value = "状态：待跟进1，进行中2，已取消3，完成4"   ) @RequestParam(value = "status", defaultValue = "-1") int status
    ) {
        Map<String, Object> pageResult = followService.uSearch(
                page, size, date, businessManagerId, status
        );
        return JsonData.buildSuccess(pageResult);
    }


    @ApiOperation("客户模块-新增跟进")
    @PostMapping(value = "uAdd", produces = "application/json;charset=UTF-8")
    public JsonData uAdd(
            @ApiParam(value = "uAdd") @RequestBody CustomerFollowDTO followDTO) {
        return followService.uAdd(followDTO);
    }

    @ApiOperation("客户模块-修改跟进")
    @PostMapping(value = "uUpdate", produces = "application/json;charset=UTF-8")
    public JsonData uUpdate(
            @ApiParam(value = "uAdd") @RequestBody CustomerFollowDTO followDTO) {
        return followService.uUpdate(followDTO);
    }

    @ApiOperation("客户模块-确认到达")
    @PostMapping(value = "uArrival", produces = "application/json;charset=UTF-8")
    public JsonData uArrival(
            @ApiParam(value = "uArrival") @RequestBody CustomerFollowDTO followDTO) {
        return followService.uArrival(followDTO);
    }

    @ApiOperation("客户模块-完成跟进")
    @PostMapping(value = "uFinish", produces = "application/json;charset=UTF-8")
    public JsonData uFinish(
            @ApiParam(value = "uFinish") @RequestBody CustomerFollowDTO followDTO) {
        return followService.uFinish(followDTO);
    }

    @ApiOperation("客户模块-跟进详情")
    @GetMapping("uDetail")
    public JsonData uDetail(
            @ApiParam(value = "跟进任务编号") @RequestParam(value = "followNo", defaultValue = "-1") String followNo,
            @ApiParam(value = "员工id，既业务负责人id") @RequestParam(value = "businessManagerId", defaultValue = "-1") int businessManagerId,
            @ApiParam(value = "状态：待跟进1，进行中2，已取消3，完成4") @RequestParam(value = "status", defaultValue = "-1") int status
    ) {
        return followService.uDetail(
                followNo, businessManagerId, status
        );
    }

    @ApiOperation("客户模块-请求增援")
    @GetMapping("uAddBusinessManager")
    public JsonData uAddBusinessManager(
            @ApiParam(value = "跟进任务编号") @RequestParam(value = "followNo", defaultValue = "-1") String followNo,
            @ApiParam(value = "员工id，既业务负责人id") @RequestParam(value = "businessManagerId", defaultValue = "-1") int businessManagerId,
            @ApiParam(value = "业务负责人") @RequestParam(value = "businessManager", defaultValue = "-1") String businessManager,
            @ApiParam(value = "业务部门") @RequestParam(value = "businessDepartment", defaultValue = "-1") String businessDepartment,
            @ApiParam(value = "业务部门id") @RequestParam(value = "businessDepartmentId", defaultValue = "-1") int businessDepartmentId,
            @ApiParam(value = "业务负责人电话") @RequestParam(value = "businessPhone", defaultValue = "-1") String businessPhone

    ) {
        return followService.uAddBusinessManager(
                followNo, businessManagerId, businessManager, businessDepartmentId, businessDepartment, businessPhone
        );
    }
}

